import {Router} from 'express';
import ReportHour from "../db/entity/ReportHour";
import {Op} from 'sequelize';

let router = Router();

router.get('/', report);

async function query(start, end) {
    let startDate = new Date(start);
    startDate.setMinutes(startDate.getMinutes() + 5);

    let hour = await ReportHour.findAll({
        where: {
            [Op.and]: [
                {
                    createAt: {
                        [Op.gt]: startDate
                    }
                },
                {
                    createAt: {
                        [Op.lt]: new Date(end)
                    }
                }
            ]
        },
    });
    return JSON.stringify(hour);
}

async function report(req, res) {
    let rep = await query(req.query.start, req.query.end);
    res.send(rep);
}

module.exports = router;
